package com.lb.design.pattern.prototype.shallow;

import java.util.List;

/**
 * @author lb
 * @Title: ShallowPrototype
 * @Description: TODO
 * @date 2019/03/13  14:54
 */
public class ShallowPrototype implements Prototype {
    private int age;
    private Integer a;

    public Integer getA() {
        return a;
    }

    public void setA(Integer a) {
        this.a = a;
    }

    private String name;
    private List hobbies;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List getHobbies() {
        return hobbies;
    }

    public void setHobbies(List hobbies) {
        this.hobbies = hobbies;
    }
//浅克隆实现Cloneable接口，重写clone方法也可以实现
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }

    @Override
    public Prototype clone() {
        ShallowPrototype shallowPrototype = new ShallowPrototype();
        shallowPrototype.setAge(this.age);
        shallowPrototype.setName(this.name);
        shallowPrototype.setHobbies(this.hobbies);
        shallowPrototype.setA(this.a);
        return shallowPrototype;
    }
}
